﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="To-do List" %>

<asp:Content ID="Content1" ContentPlaceHolderID="content" Runat="Server">

<asp:ScriptManager ID="sm" runat="server" />

<strong>State:</strong>

<asp:DropDownList ID="ddlState" runat="server" AutoPostBack="true">
    <asp:ListItem Selected="True" Text="Active" Value="false" />
    <asp:ListItem Text="Closed" Value="true" />
</asp:DropDownList>

<h2>Tasks</h2>

<asp:UpdatePanel ID="upTasks" runat="server">
    <ContentTemplate>
        <asp:GridView ID="gvTasks" runat="server" DataSourceID="odsTasks" DataKeyNames="TaskID" AutoGenerateColumns="false" AllowPaging="true">
            <Columns>
                <asp:BoundField HeaderText="Title" DataField="Title" ReadOnly="true" />
                <asp:TemplateField HeaderText="Complete">
                    <ItemTemplate>
                        <asp:CheckBox ID="cbI" runat="server" Checked='<%# Bind("complete") %>' Enabled="false" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:CheckBox ID="cbE" runat="server" Checked='<%# Bind("complete") %>' />
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowEditButton="true" />
                <asp:CommandField ShowDeleteButton="true" />
            </Columns>
        </asp:GridView>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlState" />
    </Triggers>
</asp:UpdatePanel>

<asp:UpdateProgress ID="upPrgTasks" runat="server" AssociatedUpdatePanelID="upTasks">
    <ProgressTemplate>
        <span class="loading">Please wait...</span>
    </ProgressTemplate>
</asp:UpdateProgress>

<h2>Add a Task</h2>

<asp:UpdatePanel ID="upAddTask" runat="server">
    <ContentTemplate>
        <asp:FormView ID="fvTask" runat="server" DataSourceID="odsTasks" DefaultMode="Insert">
            <InsertItemTemplate>
                <strong>Title:</strong>
                <asp:TextBox ID="txtTitle" runat="server" Text='<%# Bind("title") %>' />
                <strong>Complete:</strong>
                <asp:CheckBox ID="cbComplete" runat="server" Checked='<%# Bind("complete") %>' />
                <asp:LinkButton ID="lbAdd" runat="server" Text="Add Task" CommandName="Insert" />
            </InsertItemTemplate>
        </asp:FormView>
    </ContentTemplate>
</asp:UpdatePanel>

<asp:UpdateProgress ID="upPrgAddTask" runat="server" AssociatedUpdatePanelID="upAddTask">
    <ProgressTemplate>
        <span class="loading">Adding task...</span>
    </ProgressTemplate>
</asp:UpdateProgress>

<asp:ObjectDataSource ID="odsTasks" runat="server" TypeName="Org.GBarnett.Todo.Bll.Tasks" SelectMethod="GetTasksByState" InsertMethod="AddTask" 
    UpdateMethod="UpdateTaskState" DeleteMethod="DeleteTask">
    <SelectParameters>
        <asp:ControlParameter ControlID="ddlState" PropertyName="SelectedValue" Name="complete" Type="boolean" />
    </SelectParameters>
    <InsertParameters>
        <asp:Parameter Name="title" Type="string" />
        <asp:Parameter Name="complete" Type="boolean" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="taskId" Type="int32" />
        <asp:Parameter Name="complete" Type="boolean" />
    </UpdateParameters>
    <DeleteParameters>
        <asp:Parameter Name="taskId" Type="int32" />
    </DeleteParameters>
</asp:ObjectDataSource>

</asp:Content>

